package com.wxd.service.impl;

import com.wxd.BookService;
import com.wxd.controller.Result;
import com.wxd.dao.BookDao;
import com.wxd.domain.Book;
import com.wxd.exception.SystemException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookServiceImpl implements BookService {
    @Autowired
    private BookDao bookdao;

    public boolean save(Book book) {
        return bookdao.save(book) > 0;
    }

    public boolean delete(Integer id) {
        return bookdao.delete(id) > 0;
    }

    public boolean update(Book book) {
        return bookdao.update(book) > 0;
    }

    public Book getById(Integer id) {
        if(id == 1) {
            throw new SystemException(666,"系统异常");
        }
        return bookdao.getById(id);
    }

    public List<Book> getAllBooks() {
        return bookdao.getAll();
    }
}
